package com.itqf.quartz;

import com.itqf.job.LogJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * projectName: logandquratz2103
 *
 * @author: 赵伟风
 * time: 2021/7/6 15:03
 * description:
 */
public class SimperUse {


    public static void main(String[] args) throws SchedulerException {

        //1.创建jobdetail
        /**
         * newJob(job类.class)
         */
        JobDetail jobDetail = JobBuilder.newJob(LogJob.class).build();
        //2.创建simpletrigger
        /**
         * 每五秒执行一次! 执行4次!
         *  TriggerBuilder.newTrigger().startAt(Date) //指定的时间开启
         *                              startNow() //立即开启
         *                              endAt(Date) //结束时间
         *                              .withSchedule(定义定时规则)
         *                              执行的次数等于设置的情况+1
         *                              SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).withRepeatCount(4)
         */
        SimpleTrigger simpleTrigger = TriggerBuilder.newTrigger().startNow()
                                        .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).withRepeatCount(3)).build();
        //3.创建scheduler创建
        StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = stdSchedulerFactory.getScheduler();

        //4.将jobdetail和simplegtrigger装入scheduler
        scheduler.scheduleJob(jobDetail, simpleTrigger);
        //5.启动scheduler
        scheduler.start();

    }

}
